package com.sansecy.video.player.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.sansecy.video.R;

public class LockView extends ImageView {

    public LockView(Context context) {
        super(context);
    }

    public LockView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    private boolean mLock;

    public void setLock(boolean lock) {
        mLock = lock;
        if (lock) {
            setImageResource(R.drawable.ic_lock);
        } else {
            setImageResource(R.drawable.ic_unlock);
        }
    }

    public boolean isLock() {
        return mLock;
    }

    public boolean isShowing() {
        return getVisibility() == View.VISIBLE;
    }

    public void hide() {
        setVisibility(GONE);
    }

    public void show() {
        setVisibility(VISIBLE);
        removeCallbacks(mHideLockViewRunnable);
        postDelayed(mHideLockViewRunnable, 3000);
    }

    Runnable mHideLockViewRunnable = new Runnable() {
        @Override
        public void run() {
            hide();
        }
    };

}
